Skip to content

ILLDEV-463 Add batch action cleanup - #692

Merged
JanisSaldabols merged 4 commits into
mainfrom
ILLDEV-463
Jul 30, 2026
Merged

ILLDEV-463 Add batch action cleanup#692
JanisSaldabols merged 4 commits into
mainfrom
ILLDEV-463

Conversation

@JanisSaldabols

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings July 27, 2026 06:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds retention-based cleanup for batch action “run” events so the event table doesn’t grow indefinitely per scheduled batch task, and centralizes an int -> int32 clamping helper in broker/common.

Changes:

  • Add a new SQLC query + scheduler repo method to delete old batch action runs beyond a configurable retention limit.
  • Wire SchedRepo into BatchActionService and invoke cleanup before dispatching the batch action handler.
  • Move ToInt32 clamping helper into broker/common and update call sites.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
broker/test/service/supplierlocator_test.go Switches int→int32 conversion to common.ToInt32.
broker/sqlc/event_query.sql Adds DeleteOldBatchActionRunEvents query for retention cleanup.
broker/service/supplierlocator.go Uses common.ToInt32 and removes local helper.
broker/scheduler/service/batch_action.go Adds retention env var, injects scheduler repo, and performs cleanup before dispatch.
broker/scheduler/service/batch_action_test.go Updates constructor calls and adds tests for cleanup behavior.
broker/scheduler/db/repo.go Exposes DeleteOldBatchActionRunEvents on SchedRepo and implements it.
broker/README.md Documents BATCH_ACTION_RUN_RETENTION env var and reflows the env table.
broker/common/common.go Adds shared ToInt32 clamping helper.
broker/app/app.go Creates schedRepo once and wires it into BatchActionService and scheduler API/scheduler startup.
Comments suppressed due to low confidence (1)

broker/scheduler/service/batch_action_test.go:186

  • This test mutates the package-global BATCH_ACTION_RUN_RETENTION and resets it to 5, which may not be the original value (it can be overridden via env). Capture the original value and restore it via t.Cleanup to avoid leaking state across tests.
	BATCH_ACTION_RUN_RETENTION = 0

	status, result := svc.batchAction(testCtx, requestAgingEvent("cql.allRecords=1", map[string]any{"interval": "24h"}))

	assert.Equal(t, events.EventStatusSuccess, status)
	assert.NotNil(t, result)
	assert.False(t, cleanupRepo.called)
	assert.True(t, repo.listCalled)
	BATCH_ACTION_RUN_RETENTION = 5

Comment thread broker/sqlc/event_query.sql Outdated
Comment thread broker/scheduler/service/batch_action_test.go
Comment thread broker/sqlc/event_query.sql Outdated
Comment thread broker/sqlc/event_query.sql Outdated
Comment thread broker/sqlc/event_query.sql Outdated
Comment thread broker/scheduler/db/repo.go
@jakub-id

Copy link
Copy Markdown
Contributor

@JanisSaldabols it makes sense to leave the invoke-background-action events since they will be cleaned up when we clean up (archive) patron requests. Let's just clean up the parent field for this event so that we don't have dangling reference when the parent invoke-batch-action event is cleaned up.

@jakub-id jakub-id left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with the above change request.

@JanisSaldabols
JanisSaldabols enabled auto-merge (squash) July 30, 2026 07:22
@JanisSaldabols
JanisSaldabols merged commit 1c9287a into main Jul 30, 2026
5 checks passed
@JanisSaldabols
JanisSaldabols deleted the ILLDEV-463 branch July 30, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants